import './admin.scss'
import LeftNav from "../../components/layout/left-nav/LeftNav";
import HeaderBar from "../../components/layout/Header/HeaderBar";
import FooterBar from "../../components/layout/footer-bar/FooterBar";

import Home from "../demo/home/Home";
import Analysis from "../demo/dashboard/analysis/Analysis";
import Monitor from "../demo/dashboard/monitor/Monitor";
import Workspace from "../demo/dashboard/wordplace/Workspace";
import BaseForm from "../demo/form/baseform/BaseForm";
import StepForm from "../demo/form/stepform/StepForm";
import AdvancedForm from "../demo/form/advanced-form/AdvancedForm";

import React, {Component} from 'react'
import MemoryUtil from "../../util/MemoryUtil";
import {Redirect, Route, Switch} from 'react-router-dom'

import {Layout} from 'antd'

const {Footer, Sider, Content} = Layout


/**
 * 后台页面的路由组件
 */
export default class Admin extends Component {
    render() {
        const user = MemoryUtil.user
        // 如果 user 不存在说明没有登录, 跳转到登录页
        if (!user || !user.uid) {
            return < Redirect to='/login'/>
        }
        return (
            <Layout className="container">
                <Sider>
                    <LeftNav/>
                </Sider>
                <Layout>
                    <HeaderBar />
                    <Content style={{backgroundColor: '#ffffff'}}>
                        <Switch>
                            <Route path='/home' component={Home} />
                            <Route path='/dashboard/analysis' component={Analysis} />
                            <Route path='/dashboard/monitor' component={Monitor} />
                            <Route path='/dashboard/workspace' component={Workspace} />
                            <Route path='/form/base-form' component={BaseForm} />
                            <Route path='/form/step-form' component={StepForm} />
                            <Route path='/form/advanced-form' component={AdvancedForm} />
                            <Redirect to='/home'/>
                        </Switch>
                    </Content>
                    <Footer><FooterBar /></Footer>
                </Layout>
            </Layout>
        )
    }
}
